package com.youku.controls
{
   import com.youku.plugins.explugin.ExPluginFacade;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import com.youku.events.PluginEvent;
   import com.youku.events.CoreEvent;
   import com.youku.events.ExPluginControlEvent;
   import com.youku.events.PlayerControlEvent;
   import com.youku.data.PlayerConstant;
   
   public class ExPluginController extends BasePluginController
   {
      
      public function ExPluginController() {
         super();
         this.init();
      }
      
      private var _exPluginFacade:ExPluginFacade;
      
      override protected function init() : void {
         this._exPluginFacade = ExPluginFacade.getInstance();
         this._exPluginFacade.init(viewManager.controlsLayer,playerProxy);
         GlobalService.addService(GlobalServiceKeys.EXPLUGIN_FACADE,this._exPluginFacade);
         playerProxy.addEventListener(PluginEvent.EX_ADD_BUTTON_CAPTION,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_ADD_BUTTON_THREED,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_ADD_DEPENDECE,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_REMOVE_DEPENDECE,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_THREED_RENDER,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_THREED_HIDE,this.onExPluginEvent);
         playerProxy.addEventListener(PluginEvent.EX_CAPTION_HIDE,this.onExPluginEvent);
         playerProxy.addEventListener(CoreEvent.GOT_METADATA,this.onCoreEvent);
      }
      
      private function onCoreEvent(param1:CoreEvent) : void {
         switch(param1.type)
         {
            case CoreEvent.GOT_METADATA:
               playerProxy.dispatchEvent(new ExPluginControlEvent(ExPluginControlEvent.PLUGIN_METADATA));
               break;
         }
      }
      
      private function onExPluginEvent(param1:PluginEvent) : void {
         var _loc2_:Object = null;
         var _loc3_:* = false;
         switch(param1.type)
         {
            case PluginEvent.EX_ADD_BUTTON_THREED:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CONTROLBAR_ADD_BUTTON_THRRED));
               break;
            case PluginEvent.EX_ADD_BUTTON_CAPTION:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CONTROLBAR_ADD_BUTTON_CAPTION));
               break;
            case PluginEvent.EX_ADD_DEPENDECE:
               _loc2_ = param1.data;
               facadeManager.addInitDependence(_loc2_);
               break;
            case PluginEvent.EX_REMOVE_DEPENDECE:
               _loc2_ = param1.data;
               facadeManager.removeInitDependence(_loc2_);
               break;
            case PluginEvent.EX_THREED_RENDER:
               _loc3_ = true;
               if((param1.data) && param1.data.stop == false)
               {
                  _loc3_ = false;
               }
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_OTHER_RENDER,{"stop":_loc3_}));
               break;
            case PluginEvent.EX_THREED_HIDE:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.AFTER_CLOSE_PANELS,{"panel":PlayerConstant.PANEL_THREED}));
               break;
            case PluginEvent.EX_CAPTION_HIDE:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.AFTER_CLOSE_PANELS,{"panel":PlayerConstant.PANEL_CAPTION}));
               break;
         }
      }
   }
}
